<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>广告运营管理</el-breadcrumb-item>
        <el-breadcrumb-item>
          <a href="#" @click="$router.go(-1)">
            广告配置
          </a>
        </el-breadcrumb-item>
        <el-breadcrumb-item>{{ $route.query.name }}-书籍详情</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        :option="option"
        v-model="form"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
      >
        <template slot="last" slot-scope="scope">
          {{ scope.row.edit_time }}
          <!-- <el-tag>{{ scope.row.last_update_info }}</el-tag> -->
        </template>
        <template slot="menuLeft">
          <el-tag>数据共{{ data.length }}条</el-tag>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { adShowBook as baseURL } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10,
      },
      type: true,
      data: [],
      totalData: [],
      params: {},
      form: {},
      option: {
        addBtn: false,
        menu:false,
        column: [
          {
            label: "书籍id",
            prop: "book_id",
            type: "number",
            search: true,
            placeholder: "书籍id",
            rules: [
              {
                required: true,
                message: "请输入书籍id",
              },
            ],
          },
          {
            label: "书籍名称",
            prop: "book_title",
            type: "input",
            search: false,
            readonly: true,
            placeholder: "书籍名称",
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
            editDisabled: false,
            readonly: true,
          },
          {
            label: "最后操作信息",
            prop: "last",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
            editDisabled: false,
            readonly: true,
            slot: true,
          },
        ],
      },
    };
  },
  methods: {
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(
        `${baseURL.getBookInfoList}/${this.$route.query.id}/${this.$route.query.type}`,
        this.params,
        "GET"
      );
      response.data.forEach((e, index) => (e.sort = index + 1));
      this.data = response.data;
      this.totalData = response.data;
      this.loading = false;
    },
    /**刷新 */
    refreshChange() {
      this.getList();
    },
    /**搜索 */
    searchChange(params, done) {
      if (params.book_id) {
        this.data = this.totalData.filter(
          (e) => (e.book_id + "").indexOf(params.book_id) != -1
        );
      } else {
        this.data = this.totalData;
      }
      if (done) done();
    },
  },
};
</script>

<style>
</style>